package com.example.forum.dao;

import com.example.forum.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserDao {
    //根据id查询一个user
    @Select("select * from user where id=#{id}")
    public User findById(Integer id);

    //根据用户名查询一个User
    @Select("select * from user where username=#{username}")
    public User findByUsername(String username);

    //根据邮箱查询一个User
    @Select("select * from user where email=#{email}")
    public User findByEmail(String email);

    //注册一个用户
    @Insert("insert into user values(null,#{username},#{password},#{salt},#{email},#{type},#{status},#{activationCode},#{headerUrl},#{createTime})")
    public void register(User user);

    //激活用户
    @Update("update user set status=1 where activation_code=#{activeCode} and id=#{id}")
    public void active(@Param("activeCode") String activeCode,@Param("id") int id);

    //用户上传头像
    @Update("update user set header_url=#{headerUrl} where id=#{id}")
    public void upHeaderImage(@Param("headerUrl") String headerUrl,@Param("id") int id);

    //修改密码
    @Update("update user set password=#{newPassword} where id=#{id}")
    public void updatePassword(@Param("id") int id,@Param("newPassword") String newPassword);

    //用户登录
//    @Select("select * from user where username=#{username} and password=#{password}")
//    public User login(@Param("username") String username,@Param("password") String password);
}
